﻿using BouncingBallGame.Models;
using BouncingBallGame.ViewModels.ShapeViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BouncingBallGame.Helpers
{
    public static class ModelsConverter
    {
        public static BallViewModel ToViewModel(this BallModel ballModel)
        {
            return new BallViewModel(ballModel.X, ballModel.Y, ballModel.Radius, ballModel.NormalCollisionSpeedLoss, ballModel.TangentCollisionSpeedLoss);
        }

        public static BallModel ToModel(this BallViewModel ballVM, double scaleFactor = 1)
        {
            return new BallModel()
            {
                X = ballVM.XCenter * scaleFactor,
                Y = ballVM.YCenter * scaleFactor,
                Radius = ballVM.Radius * scaleFactor,
                NormalCollisionSpeedLoss = ballVM.NormalSpeedLoss,
                TangentCollisionSpeedLoss = ballVM.TangentSpeedLoss
            };
        }

        public static GiftViewModel ToViewModel(this GiftModel giftModel)
        {
            return new GiftViewModel(giftModel.X, giftModel.Y, giftModel.Height, giftModel.Width, giftModel.Rotation);
        }

        public static GiftModel ToModel(this GiftViewModel giftVM, double scaleFactor = 1)
        {
            return new GiftModel()
            {
                X = giftVM.X * scaleFactor,
                Y = giftVM.Y * scaleFactor,
                Height = giftVM.Height * scaleFactor,
                Width = giftVM.Width * scaleFactor,
                Rotation = giftVM.Rotation,
            };
        }

        public static ObstacleViewModel ToViewModel(this ObstacleModel obstacleModel)
        {
            return new ObstacleViewModel(obstacleModel.X, obstacleModel.Y, obstacleModel.Height, obstacleModel.Width, obstacleModel.Rotation);
        }

        public static ObstacleModel ToModel(this ObstacleViewModel obstacleVM, double scaleFactor = 1)
        {
            return new ObstacleModel()
            {
                X = obstacleVM.X * scaleFactor,
                Y = obstacleVM.Y * scaleFactor,
                Height = obstacleVM.Height * scaleFactor,
                Width = obstacleVM.Width * scaleFactor,
                Rotation = obstacleVM.Rotation,
            };
        }
    }
}
